package org.example.mcp.controller;

import jakarta.annotation.Resource;
import org.example.mcp.server.ToolServer;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author liyishan
 * @date 2025/6/29
 * @description
 */
@RestController
public class AIController {
    private final ChatClient chatClient;
    @Resource
    private ToolServer toolServer;

    public AIController(ChatClient.Builder chatClientBuilder) {
        this.chatClient = chatClientBuilder.build();
    }

    @GetMapping("/chat")
    public String chat(@RequestParam("message") String message) {
        return chatClient.prompt()
            .user(message)
            .call()
            .content();
    }

    @GetMapping("/llmOrchestrate")
    public String llmOrchestrate(@RequestParam String prompt) {
        // 按用户需求重写system prompt，突出多步自动编排
        String systemPrompt = "调用工具生成文章并保存";
        return chatClient.prompt()
            .system(systemPrompt)
            .user(prompt)
            .tools(toolServer)
            .call()
            .content();
    }

}
